package uvt.gui.mainframe.object;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class InfoFrame extends JFrame implements ActionListener {
	
	public InfoFrame(String title,String msg) {
		super(title);
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation((int)(screen.getWidth() / 2 - 125),
				    (int)(screen.getHeight() / 2 - 75));
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setMinimumSize(new Dimension(250,150));
		setResizable(false);
		setLayout(new BorderLayout());
		
		JLabel lbl = new JLabel(msg);
		JPanel p1 = new JPanel(new FlowLayout());
		p1.setBackground(Color.white);
		p1.add(lbl);
		add(p1,BorderLayout.CENTER);
		
		JButton btn = new JButton("OK");
		JPanel p2 = new JPanel(new FlowLayout());
		p2.setBackground(Color.white);
		p2.add(btn);
		btn.addActionListener(this);
		btn.addKeyListener(new KeyListener() {
			public void keyPressed(KeyEvent ke) {
				if(ke.getKeyCode() == KeyEvent.VK_ENTER) {
					dispose();
				}
			}
			public void keyTyped(KeyEvent ke) {
			}			
			public void keyReleased(KeyEvent ke) {
			}
		});
		add(p2,BorderLayout.SOUTH);	
		pack();
		setVisible(true);
	}
	
	public void actionPerformed(ActionEvent ac) {
		dispose();
	}
}
